package cn.mythreadtest.test6case2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MyThread extends Thread{
    List<Integer> list;
    public MyThread(List<Integer> list){
        this.list = list;
    }
    @Override
    public void run() {
        List<Integer> boxList = new ArrayList<>();
        while (true){
            synchronized (MyThread.class){
                if(list.size() == 0){
                    System.out.println(getName() + boxList);
                    break;
                }else{
                    Collections.shuffle(list);
                    Integer prize = list.remove(0);
                    boxList.add(prize);
                }
            }
        }
    }
}
